package com.woyou.ui.activity.orderdetail;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.citaq.ideliver.R;
import com.woyou.bean.Comment;
import com.woyou.bean.OrderDetail;
import com.woyou.utils.DateUtils;

/**
 * 订单已评论
 * @author
 *
 */
public class OrderCommentCreater extends StateViewCreater implements OnClickListener {

	public OrderCommentCreater(Context context, ViewControl uiControl, OrderDetail detail) {
		super(context, uiControl, detail);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub

	}

	@Override
	protected void createView() {
		mViewArr = new View[1];
		
		View view = View.inflate(mContext, R.layout.orderdetial_item_comment, null);
		TextView timeText = (TextView) view.findViewById(R.id.t1);
		TextView commentText = (TextView) view.findViewById(R.id.t2);
		ImageView startImage = (ImageView) view.findViewById(R.id.evaluation_start);
		RelativeLayout recommentRl = (RelativeLayout) view.findViewById(R.id.recomment_rl);
		TextView retimeText = (TextView) view.findViewById(R.id.t4);
		TextView recommentText = (TextView) view.findViewById(R.id.t5);
		
		String yestoryDate = DateUtils.getYestoryDate();
		String todayDate = DateUtils.getTodayDate();
		
		Comment comment = mDetail.getComment();
		if(comment!=null){
			String cnowDate = DateUtils.formatDate(comment.getcTime());
			String cstr ="";
			if(yestoryDate.equals(cnowDate)){
				cstr = "昨天 " + DateUtils.getTime(comment.getcTime());
			} else if(todayDate.equals(cnowDate)){
				cstr = DateUtils.getTime(comment.getcTime());
			} else {
				cstr = cnowDate.substring(5, 10) + " " + DateUtils.getTime(comment.getcTime());
			}
			timeText.setText(cstr);
			commentText.setText(comment.getComment());
			setStartLevel(startImage, comment.getScore());
			
			if(TextUtils.isEmpty(comment.getReCommnet())){
				recommentRl.setVisibility(View.GONE);
			} else {
				String rnowDate = DateUtils.formatDate(comment.getReTime());
				String rstr ="";
				if(yestoryDate.equals(rnowDate)){
					rstr = "昨天 " + DateUtils.getTime(comment.getReTime());
				} else if(todayDate.equals(rnowDate)){
					rstr = DateUtils.getTime(comment.getReTime());
				} else {
					rstr = rnowDate.substring(5, 10) + " " + DateUtils.getTime(comment.getReTime());
				}
				
				recommentRl.setVisibility(View.VISIBLE);
				retimeText.setText(rstr);
				recommentText.setText(comment.getReCommnet());
			}
		}
		
		mViewArr[0] = view;
	}

	private void setStartLevel(ImageView start, float value) {
		if (0.0 == value) {
			start.setImageResource(R.raw.start0);
		} else if (2.0 >= value) {
			start.setImageResource(R.raw.start1);
		} else if (4.0 >= value) {
			start.setImageResource(R.raw.start2);
		} else if (6.0 >= value) {
			start.setImageResource(R.raw.start3);
		} else if (8.0 >= value) {
			start.setImageResource(R.raw.start4);
		} else if (10.0 >= value) {
			start.setImageResource(R.raw.start5);
		} else {
			start.setImageResource(R.raw.start5);
		}
	}

}
